<template>
	<view class="page">
		<!-- 粘性头部区域：积分余额卡片 + 筛选选项 -->
		<view class="sticky-header">
			<!-- 积分余额卡片 -->
			<view class="points-summary">
				<view class="summary-card">
					<view class="card-header">
						<view class="points-info">
							<text class="current-points">{{ currentPoints }}</text>
							<text class="points-label">我的积分</text>
						</view>
						<view class="points-icon">
							<image src="/static/svg/trend-up.svg" class="trend-icon" />
						</view>
					</view>
					
					<view class="card-footer">
						<view class="action-btn" @click="showPointsRule">
							<image src="/static/svg/comprehensive.svg" class="action-icon" />
							<text class="action-text">积分规则</text>
						</view>
						<view class="action-btn primary" @click="pointsExchange">
							<image src="/static/svg/gift.svg" class="action-icon" />
							<text class="action-text">积分兑换</text>
						</view>
					</view>
				</view>
			</view>

			<!-- 筛选选项 -->
			<view class="filter-section">
				<scroll-view class="filter-scroll" scroll-x="true">
					<view class="filter-list">
						<view 
							v-for="(item, index) in filterOptions" 
							:key="index"
							class="filter-item"
							:class="{ active: activeFilter === index }"
							@click="changeFilter(index)"
						>
							{{ item.label }}
						</view>
					</view>
				</scroll-view>
			</view>
		</view>

		<!-- 积分记录列表 -->
		<view class="records-section">
			<view v-if="filteredRecords.length === 0" class="empty-state">
				<image src="/static/svg/comprehensive.svg" class="empty-icon" />
				<text class="empty-text">暂无积分记录</text>
			</view>
			<view v-else class="records-list">
				<view 
					v-for="(record, index) in filteredRecords" 
					:key="index" 
					class="record-item"
				>
					<view class="record-left">
						<view class="record-icon-container" :class="record.type">
							<image :src="record.icon" class="record-icon" />
						</view>
						<view class="record-info">
							<text class="record-title">{{ record.title }}</text>
							<text class="record-desc">{{ record.desc }}</text>
							<text class="record-time">{{ record.time }}</text>
						</view>
					</view>
					<view class="record-right">
						<text class="record-points" :class="record.type">
							{{ record.type === 'earn' ? '+' : '-' }}{{ record.points }}
						</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 加载更多 -->
		<view class="load-more" v-if="hasMore && filteredRecords.length > 0">
			<text class="load-more-text" @click="loadMore">加载更多</text>
		</view>
	</view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';

// 当前积分
const currentPoints = ref('2,580');

// 筛选选项
const filterOptions = ref([
	{ label: '全部', value: 'all' },
	{ label: '获得', value: 'earn' },
	{ label: '消耗', value: 'spend' }
]);

// 当前选中的筛选项
const activeFilter = ref(0);

// 是否还有更多数据
const hasMore = ref(true);

// 积分记录数据
const pointsRecords = ref([
	{
		id: 1,
		title: '每日签到奖励',
		desc: '连续签到第7天',
		time: '2024-01-15 09:30',
		points: 20,
		type: 'earn',
		icon: '/static/svg/gift.svg'
	},
	{
		id: 2,
		title: '发布活动',
		desc: '发布了"周末徒步活动"',
		time: '2024-01-14 16:20',
		points: 50,
		type: 'earn',
		icon: '/static/svg/walking.svg'
	},
	{
		id: 3,
		title: '参与活动',
		desc: '参加了"摄影分享会"',
		time: '2024-01-14 14:15',
		points: 30,
		type: 'earn',
		icon: '/static/svg/camera.svg'
	},
	{
		id: 4,
		title: '积分兑换',
		desc: '兑换了优惠券',
		time: '2024-01-13 20:30',
		points: 100,
		type: 'spend',
		icon: '/static/svg/gift.svg'
	},
	{
		id: 5,
		title: '评论互动',
		desc: '在活动中发表了精彩评论',
		time: '2024-01-13 11:45',
		points: 10,
		type: 'earn',
		icon: '/static/svg/comment.svg'
	},
	{
		id: 6,
		title: '每日签到奖励',
		desc: '连续签到第6天',
		time: '2024-01-12 08:15',
		points: 15,
		type: 'earn',
		icon: '/static/svg/gift.svg'
	},
	{
		id: 7,
		title: '分享活动',
		desc: '分享了"户外烧烤聚会"',
		time: '2024-01-11 19:22',
		points: 25,
		type: 'earn',
		icon: '/static/svg/share.svg'
	},
	{
		id: 8,
		title: '活动打卡',
		desc: '在"晨跑打卡"中完成打卡',
		time: '2024-01-10 07:30',
		points: 15,
		type: 'earn',
		icon: '/static/svg/trend-up.svg'
	}
]);

// 根据筛选条件过滤记录
const filteredRecords = computed(() => {
	const filterValue = filterOptions.value[activeFilter.value].value;
	if (filterValue === 'all') {
		return pointsRecords.value;
	}
	return pointsRecords.value.filter(record => record.type === filterValue);
});

// 切换筛选条件
const changeFilter = (index) => {
	activeFilter.value = index;
};

// 加载更多数据
const loadMore = () => {
	uni.showToast({
		title: '加载中...',
		icon: 'loading',
		duration: 1000
	});
	
	setTimeout(() => {
		hasMore.value = false;
		uni.showToast({
			title: '没有更多了',
			icon: 'none'
		});
	}, 1000);
};

// 显示积分规则
const showPointsRule = () => {
	uni.showModal({
		title: '积分规则',
		content: '1. 每日签到获得10-20积分\n2. 发布活动获得50积分\n3. 参与活动获得20-30积分\n4. 评论互动获得10积分\n5. 分享活动获得25积分\n6. 活动打卡获得15积分\n7. 100积分=1元',
		showCancel: false,
		confirmText: '知道了'
	});
};

// 积分兑换
const pointsExchange = () => {
	uni.showToast({
		title: '积分兑换功能开发中',
		icon: 'none'
	});
};

onMounted(() => {
	// 页面加载时可以获取最新的积分数据
});
</script>

<style scoped>
.page {
	min-height: 100vh;
	background: #f8f9fa;
	padding-bottom: 20px;
}

/* 粘性头部区域 */
.sticky-header {
	position: sticky;
	top: 0;
	z-index: 100;
	background: #f8f9fa;
	padding-bottom: 15px;
}

/* 积分余额卡片 */
.points-summary {
	padding: 20px 20px 0;
}

.summary-card {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-radius: 20px;
	padding: 26px;
	color: white;
	position: relative;
	overflow: hidden;
	box-shadow: 0 12px 24px rgba(102, 126, 234, 0.25);
}

.card-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 24px;
}

.points-info {
	display: flex;
	flex-direction: column;
}

.current-points {
	font-size: 36px;
	font-weight: 700;
	margin-bottom: 4px;
	letter-spacing: -1px;
}

.points-label {
	font-size: 16px;
	font-weight: 500;
	opacity: 0.85;
}

.points-icon {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.15);
	display: flex;
	align-items: center;
	justify-content: center;
}

.trend-icon {
	width: 22px;
	height: 22px;
	filter: brightness(0) invert(1);
	opacity: 0.9;
}

.card-footer {
	display: flex;
	gap: 12px;
}

.action-btn {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 18px;
	border-radius: 16px;
	font-size: 14px;
	color: white;
	background: rgba(255, 255, 255, 0.1);
	border: 1px solid rgba(255, 255, 255, 0.2);
	transition: all 0.3s ease;
	flex: 1;
	justify-content: center;
}

.action-btn:active {
	transform: scale(0.96);
	background: rgba(255, 255, 255, 0.2);
}

.action-btn.primary {
	background: rgba(255, 255, 255, 0.2);
	border: 1px solid rgba(255, 255, 255, 0.3);
}

.action-btn.primary:active {
	background: rgba(255, 255, 255, 0.3);
}

.action-icon {
	width: 18px;
	height: 18px;
	filter: brightness(0) invert(1);
	opacity: 0.9;
}

.action-text {
	font-size: 14px;
	font-weight: 500;
}

/* 筛选选项 */
.filter-section {
	padding: 15px 20px 0;
}

.filter-scroll {
	white-space: nowrap;
}

.filter-list {
	display: flex;
	gap: 15px;
}

.filter-item {
	padding: 8px 20px;
	background: white;
	border-radius: 20px;
	font-size: 14px;
	color: #666;
	white-space: nowrap;
	transition: all 0.3s;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.filter-item.active {
	background: #667eea;
	color: white;
}

.filter-item:active {
	transform: scale(0.95);
}

/* 积分记录列表 */
.records-section {
	padding: 0 20px;
}

.empty-state {
	background: white;
	border-radius: 16px;
	padding: 60px 20px;
	text-align: center;
}

.empty-icon {
	width: 80px;
	height: 80px;
	opacity: 0.3;
	margin-bottom: 20px;
}

.empty-text {
	font-size: 16px;
	color: #999;
}

.records-list {
	background: white;
	border-radius: 16px;
	overflow: hidden;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.record-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20px;
	border-bottom: 1px solid #f8f9fa;
	transition: background-color 0.2s;
}

.record-item:last-child {
	border-bottom: none;
}

.record-item:active {
	background: #f8f9fa;
}

.record-left {
	display: flex;
	align-items: center;
	flex: 1;
}

.record-icon-container {
	width: 44px;
	height: 44px;
	border-radius: 22px;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-right: 15px;
}

.record-icon-container.earn {
	background: #e8f5e8;
}

.record-icon-container.spend {
	background: #ffeaea;
}

.record-icon {
	width: 24px;
	height: 24px;
}

.record-icon-container.earn .record-icon {
	filter: hue-rotate(120deg) saturate(1.2);
}

.record-icon-container.spend .record-icon {
	filter: hue-rotate(0deg) saturate(1.2);
}

.record-info {
	flex: 1;
}

.record-title {
	font-size: 16px;
	color: #333;
	font-weight: 500;
	display: block;
	margin-bottom: 5px;
}

.record-desc {
	font-size: 14px;
	color: #666;
	display: block;
	margin-bottom: 5px;
	line-height: 1.4;
}

.record-time {
	font-size: 12px;
	color: #999;
	display: block;
}

.record-right {
	text-align: right;
	margin-left: 15px;
}

.record-points {
	font-size: 18px;
	font-weight: bold;
}

.record-points.earn {
	color: #4caf50;
}

.record-points.spend {
	color: #f44336;
}

/* 加载更多 */
.load-more {
	padding: 20px;
	text-align: center;
}

.load-more-text {
	color: #667eea;
	font-size: 16px;
	padding: 10px 20px;
	border: 1px solid #667eea;
	border-radius: 20px;
	background: white;
	transition: all 0.3s;
}

.load-more-text:active {
	background: #667eea;
	color: white;
	transform: scale(0.95);
}
</style> 